from tw.api import WidgetsList,CSSLink
from tw.forms import FieldSet,TableForm,TableFieldSet,ListForm,ListFieldSet,CalendarDatePicker, SingleSelectField, TextField, TextArea, Spacer,CheckBox,FileField,HiddenField
from tg import url
from comboselect import ComboSelect
from tw.forms.validators import Int, NotEmpty,UnicodeString,All,ForEach,DateConverter
from datetime import date,datetime
import time
from tw.jquery.autocomplete import AutoCompleteField
from common import NakedDateConverter

class AddEventForm(TableForm):
    #template = "lifepyscle.widgets.templates.add_events"
    submit_text = "Add Event"
    hover_help = True
    action="/record/do_event_add"
    class fields(WidgetsList):
        record_id = HiddenField(id="record_id")
        AddEventFieldSet = TableFieldSet(hover_help=True,id="add_event_form_fs",template="lifepyscle.widgets.templates.table_fieldset",children=[TextField(id='event_title',label_text=u"Event Title",\
                help_text=u"Provide a title which you will be able to search for this event later"),
            AutoCompleteField(label_for=u"Event Type",id='event_type',\
                completionURL = '/record/fetch_types',\
                fetchJSON = True,\
                minChars = 3,\
                help_text=u"Start typing to choose an event type. Existing types will be shown as suggestions"),
            TextArea(id="event_description",label_text=u"Event Description:",\
                help_text=u"Provide an accurate description of the purpose of this record",\
                attrs=dict(rows=6, cols=45))])

add_event_form = AddEventForm(id="add_event_form")

from tw.jquery.activeform import AjaxForm
class EventFields(WidgetsList):
    hover_help=True
    record_id = HiddenField(id="record_id")
    title = TextField(validator=NotEmpty())
    type = AutoCompleteField(label_for=u"Event Type",id='event_type',\
                completionURL = '/record/fetch_types',\
                fetchJSON = True,\
                minChars = 3,\
                help_text=u"Start typing to choose an event type. Existing types will be shown as suggestions")
    occurs = CalendarDatePicker()
    description = TextArea(id="event_description",label_text=u"Event Description:",\
                help_text=u"Provide an accurate description of the purpose of this record",\
                attrs=dict(rows=6, cols=45))

smather='smather'
event_form = AjaxForm(id="event_form",
                    hover_help = True,
                    fields=EventFields(),
                    target="output",
                    #dataType='json',
                    action="/record/remote_add_event")

